<?php

namespace maotool\util;

class TimeUtil extends DateUtil
{

    /**
     * 获取当前小时
     *
     * @param bool $withLeadingZero 是否补零，默认true
     * @return string 当前小时
     */
    public static function currentHour($withLeadingZero = true)
    {
        return date($withLeadingZero ? 'H' : 'G');
    }

    /**
     * 获取指定时间戳的小时
     *
     * @param int|null $timestamp 时间戳，默认为当前时间
     * @param bool $withLeadingZero 是否补零，默认true
     * @return string 指定时间的小时
     */
    public static function hour($timestamp = null, $withLeadingZero = true)
    {
        if ($timestamp === null) {
            $timestamp = time();
        }
        return date($withLeadingZero ? 'H' : 'G', $timestamp);
    }

    /**
     * 获取当前分钟
     *
     * @param bool $withLeadingZero 是否补零，默认true
     * @return string 当前分钟
     */
    public static function currentMinute($withLeadingZero = true)
    {
        return date($withLeadingZero ? 'i' : 'g');
    }

    /**
     * 获取指定时间戳的分钟
     *
     * @param int|null $timestamp 时间戳，默认为当前时间
     * @param bool $withLeadingZero 是否补零，默认true
     * @return string 指定时间的分钟
     */
    public static function minute($timestamp = null, $withLeadingZero = true)
    {
        if ($timestamp === null) {
            $timestamp = time();
        }
        return date($withLeadingZero ? 'i' : 'g', $timestamp);
    }

}